package cn.hx.service.impl;

import cn.hx.controller.system.PageModel;
import cn.hx.dao.UserReportDao;
import cn.hx.entity.ItemUser;
import cn.hx.entity.UserReport;
import cn.hx.service.UserReportService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用戶申请事项办理表(UserReport)表服务实现类
 *
 * @author makejava
 * @since 2022-08-20 15:00:24
 */
@Service("userReportService")
public class UserReportServiceImpl implements UserReportService {
    @Resource
    private UserReportDao userReportDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public UserReport queryById(Integer id) {
        return this.userReportDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<UserReport> queryAllByLimit(UserReport userReport,int offset, int limit) {
        return this.userReportDao.queryAllByLimit(userReport,offset, limit);
    }

    @Override
    public List<UserReport> queryIndexReport() {
        return this.userReportDao.queryIndexReport();
    }

    @Override
    public List<UserReport> queryByLimitStatus(int offset, int limit) {
        List<UserReport> userReports = userReportDao.queryByLimitStatus(offset, limit);
        return userReports;
    }

    @Override
    public List<UserReport> dateByLimit() {
        List<UserReport> userReports = userReportDao.dateByLimit();
        return userReports;
    }

    /**
     * 查询所有
     *
     * @return 对象列表
     */
    @Override
    public List<UserReport> queryAll(UserReport userReport) {
        return this.userReportDao.queryAll(userReport);
    }

    /**
     * 新增数据
     *
     * @param userReport 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(UserReport userReport) {
        return this.userReportDao.insert(userReport);
    }

    /**
     * 修改数据
     *
     * @param userReport 实例对象
     * @return 实例对象
     */
    @Override
    public int update(UserReport userReport) {
        return this.userReportDao.update(userReport);

    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.userReportDao.deleteById(id) > 0;
    }

    @Override
    public int count(UserReport userReport) {
        return this.userReportDao.count(userReport);
    }

    @Override
    public List<UserReport> queryAllCheck(UserReport userReport) {
        List<UserReport> userReports = userReportDao.queryAllCheck(userReport);
        return userReports;
    }




    /**
     * 个人方法，请勿改动，谢谢
     * */

    @Override
    public UserReport queryOneByItemId(Integer id) {
        return userReportDao.queryOneByItemId(id);
    }

    @Override
    public PageModel<UserReport> page(UserReport userReport,int page, int size) {
        PageModel<UserReport> instance = PageModel.getInstance(page, size);
        List<UserReport> pets = userReportDao.queryAllByLimit(userReport,(page - 1) * size, size);
        int count = userReportDao.count1();
        instance.setList(pets);
        instance.setCount(count);
        instance.setPageSize(count % size == 0 ? count / size : (count / size + 1));
        return instance;
    }

    @Override
    public int selectCountByStatus() {
        return userReportDao.selectCountByStatus();
    }

    @Override
    public List<ItemUser> queryByUserId(Integer id) {
        return userReportDao.queryByUserId(id);
    }

}